import cv2 as cv
import numpy as np


def add_waight_func():
    src_img = cv.imread('Lena.png')
    icon_img = cv.imread('icon.png')
    cv.imshow('src image', src_img)
    logo_img = src_img[:72, :72]
    logo_img = cv.addWeighted(logo_img, 0.5, icon_img, 0.5, 0)
    src_img[:72, :72] = logo_img
    cv.imshow('add waight image', src_img)
    cv.waitKey(0)


def add_logo_func():
    src_img = cv.imread('Lena.png', cv.IMREAD_COLOR)
    src_icon = cv.imread('icon.png', cv.IMREAD_COLOR)

    row, col = src_icon.shape[0:2]
    logo_image = src_img[10:row+10, 10:col+10]
    icon_gray = cv.cvtColor(src_icon, cv.COLOR_BGR2GRAY)

    ret, mask_icon = cv.threshold(icon_gray, 20, 255, cv.THRESH_BINARY)

    dst_icon = cv.bitwise_and(src_icon, src_icon, mask=mask_icon)

    mask_logo = cv.bitwise_not(mask_icon)
    logo_image = cv.bitwise_and(logo_image, logo_image, mask=mask_logo)

    logo = cv.add(dst_icon, logo_image)
    src_img[10:row + 10, 10:col + 10] = logo

    cv.imshow('logo_image', src_img)
    cv.waitKey(0)



if __name__ == '__main__':
    add_waight_func()
    add_logo_func()
